package com.web.product;

import java.io.IOException;
import java.util.Calendar;
import java.util.List;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.BookingDAO;
import com.dao.BookingDetail;

@WebServlet("/Booking/List")
public class BookingList extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public BookingList() {
		 super();
	     // TODO Auto-generated constructor stub
	}
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("txt_name");
		int year = Integer.valueOf(request.getParameter("txt_year"));
		int month = Integer.valueOf(request.getParameter("ddl_month"));		
				
		Calendar c = Calendar.getInstance();		
		c.set(year,month,-1);
//		c1.add(Calendar.DAY_OF_MONTH,-1);
		
		int TotalDayInMonth = c.getActualMaximum(Calendar.DAY_OF_MONTH);
		int FirstDayWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
		
		try {
			//List<Booking> list = BookingDAO.findReserveDay(name,year, month);
			List<BookingDetail> detail = BookingDAO.GetBookingDetail(name,year, month, TotalDayInMonth, FirstDayWeek);
			
			//request.setAttribute("BookingList", list);
			request.setAttribute("BookingDetail", detail);
			request.getRequestDispatcher("/bookingList.jsp").forward(request, response);
		} catch (NumberFormatException | NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
